import 'package:flutter/material.dart';
import '../service/theme_notifier.dart';
import '../service/theme_service.dart';

class GradientAppBar extends StatelessWidget implements PreferredSizeWidget {
  final Widget title; // Changed from String to Widget
  final List<Widget>? actions;
  final bool automaticallyImplyLeading;
  final Widget? leading;
  final PreferredSizeWidget? bottom;

  const GradientAppBar({
    Key? key,
    required this.title, // Type changed to Widget
    this.actions,
    this.automaticallyImplyLeading = true,
    this.leading,
    this.bottom,
  }) : super(key: key);

  @override
  Size get preferredSize =>
      Size.fromHeight(kToolbarHeight + (bottom?.preferredSize.height ?? 0.0));

  @override
  Widget build(BuildContext context) {
    return ListenableBuilder(
      listenable: ThemeNotifier.instance,
      builder: (context, _) {
        final colors =
            ThemeService.themeColors[ThemeNotifier.instance.currentTheme]!;
        return Container(
          decoration: BoxDecoration(gradient: colors.gradient),
          child: AppBar(
            title: title, // Now directly using the Widget
            actions: actions,
            automaticallyImplyLeading: automaticallyImplyLeading,
            leading: leading,
            bottom: bottom,
            backgroundColor: Colors.transparent,
            foregroundColor: Colors.white,
          ),
        );
      },
    );
  }
}
